from django.db import models


class BookGroup(models.Model):
    """商品频道组"""
    name = models.CharField(max_length=20, verbose_name='小说分类')

    class Meta:
        db_table = 'bk_book_group'
        verbose_name = '小说分类'
        verbose_name_plural = verbose_name


class Book(models.Model):
    """小说详情"""
    name = models.CharField(max_length=20, verbose_name='小说名字')
    title = models.TextField(verbose_name='小说标题')
    author = models.CharField(max_length=20, verbose_name='作者')
    group = models.ForeignKey(BookGroup, verbose_name='分类')
    status = models.BooleanField(verbose_name='小说状态', default=False)  # 小说状态，默认是连载
    book_image = models.ImageField(verbose_name='小说封面图片地址', default="//bookcover.yuewen.com/qdbimg/349573/1010868264"
                                                                    "/150")
    content_num = models.IntegerField(verbose_name="小说字数", default=0)
    creat_time = models.DateTimeField(verbose_name="小说创建时间", null=True)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)

    class Meta:
        db_table = 'bk_book'
        verbose_name = '小说信息'
        verbose_name_plural = verbose_name


class Book_Info(models.Model):
    """小说详情"""

    content = models.TextField(verbose_name='小说内容')
    content_name = models.CharField(max_length=200, verbose_name='小说章节名字')
    order_id = models.IntegerField(verbose_name='小说章节的顺序')
    book = models.ForeignKey(Book, verbose_name='小说的外键')

    class Meta:
        db_table = 'bk_book_info'
        verbose_name = '小说详情'
        verbose_name_plural = verbose_name


class Book_Commit(models.Model):
    """小说评论详情"""

    commit = models.CharField(max_length=200, verbose_name='小说评论内容')
    chapter = models.ForeignKey(Book_Info, verbose_name='小说章节')
    author = models.ForeignKey("user.User", verbose_name="评论的作者")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'bk_book_commit'
        verbose_name = '小说详情'
        verbose_name_plural = verbose_name


class Commit_Give_like(models.Model):
    ORDER_STATUS_CHOICES = (
        (1, "点赞"),
        (2, "点踩"),
        (3, "无状态"),  # 一般是先点赞或点踩后再取消赞或踩

    )
    author = models.ForeignKey("user.User", verbose_name="点赞或点踩的作者")
    status = models.SmallIntegerField(choices=ORDER_STATUS_CHOICES, default=1, verbose_name="用户对这条评论的状态")
    book_commit = models.ForeignKey(Book_Commit, on_delete=models.PROTECT, verbose_name="对哪条评论点赞或点踩")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    is_del = models.BooleanField(default=False, verbose_name="是否删除")
